<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

	<title>Test Dijit Subscribe</title>

	<script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("doh.runner");
		dojo.require("dijit._Widget");
		dojo.require("dojo.parser");

		var numCallsInternal = 0;
		var numCallsExternal = 0;
		var externalString = "";
		var internalSubscribe = null;

		dojo.declare("dijit.MyWidget", dijit._Widget, {
			_subscribeHandlerInternal: function(){ numCallsInternal++; }
		});

		dojo.addOnLoad(function(){
			doh.register("_widgetSubscribe",
				[
					{
						name: "_Widget.subscribe - set up subscriptions",
						runTest: function(t){
							var w = dijit.byId("widget1");
							internalSubscribe = w.subscribe("/custom/event",
													"_subscribeHandlerInternal");
							w.subscribe("/custom/event", function(){
								if(this == w){
									numCallsExternal++;
								}
							});
							w.subscribe("/custom/setString", function(str){
								if(this == w){
									externalString = str;
								}
							});
							doh.is(0, numCallsInternal);
							doh.is(0, numCallsExternal);
							doh.is("", externalString);
							doh.isNot(null, internalSubscribe);
						}
					},
					{
						name: "_Widget.subscribe - publish events",
						runTest: function(t){
							var w = dijit.byId("widget1");
							dojo.publish("/custom/event", []);
							doh.is(1, numCallsInternal);
							doh.is(1, numCallsExternal);
							dojo.publish("/custom/setString", ["myString"]);
							doh.is("myString", externalString);
							dojo.publish("/custom/setString", ["anotherString"]);
							doh.is("anotherString", externalString);
						}
					},
					{
						name: "_Widget.unsubscribe",
						runTest: function(t){
							var w = dijit.byId("widget1");
							dojo.publish("/custom/event", []);
							doh.is(2, numCallsInternal);
							doh.is(2, numCallsExternal);
							w.unsubscribe(internalSubscribe);
							dojo.publish("/custom/event", []);
							doh.is(2, numCallsInternal);
							doh.is(3, numCallsExternal);
						}
					},
					{
						name: "_Widget.destroy",
						runTest: function(t){
							var w = dijit.byId("widget1");
							w.destroy();
							dojo.publish("/custom/event", []);
							doh.is(2, numCallsInternal);
							doh.is(3, numCallsExternal);
							dojo.publish("/custom/setString", ["myString"]);
							doh.is("anotherString", externalString);
						}
					}
				]
			);
			doh.run();
		});

	</script>
</head>
<body class="tundra">
	<div id="widget1" dojoType="dijit.MyWidget"></div>
</body>
</html>
